package com.wise.site.utils;

import java.util.Hashtable;

/**
 * 全局数据缓存及交换区
 * @author huangyue
 *
 * 2012-9-17
 */
public class DataCache extends Hashtable<String, Object> {
	private static DataCache mDataCache;
	
	private DataCache(){
	}
	
	public static DataCache getInstance(){
		if(mDataCache == null){
			mDataCache = new DataCache();
		}
		
		return mDataCache;
	}
	
	
	
	public String getStringByKey(String key){
		try{
			return (String) mDataCache.get(key);
		}catch (Exception e) {
		}
		
		return null;
	}
	
	public boolean getBooleanByKey(String key, boolean defaultInt){
		try{
			return (Boolean) mDataCache.get(key);
		}catch (Exception e) {
		}
		
		return defaultInt;
	}
	
	@Override
	public synchronized Object put(String key, Object value) {
		if(value == null){
			if(containsKey(key)){
				remove(key);
			}
			return null;
		}
		return super.put(key, value);
	}
	
	public int getIntByKey(String key, int defaultInt){
		try{
			return (Integer) mDataCache.get(key);
		}catch (Exception e) {
		}
		
		return defaultInt;
	}
}
